package com.honey.mybatis.generator.entity.method;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.JavaKeyWord;
import com.honey.compilation.java.MethodDecoration;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Column;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.utils.JavaBeansUtil;
import com.honey.mybatis.generator.AbstractMethod;
import com.honey.mybatis.generator.MybatisPlugin;

public class GetterMethod extends AbstractMethod {

	private Column column = null;
	
//	private String fieldName = null;
//	
//	private FullyQualifiedJavaType fieldType = null;
//	
	
	public GetterMethod(AbstractJavaCompilation clazz,
			MybatisPlugin belongPlugin, IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(clazz, belongPlugin, introspectSchema, introspectSchemaColumn);
	}
	
	@Override
	protected String getMethodName() {
		return JavaBeansUtil.getGetterMethodName(
			super.getMethodName(column),
			column.getFullyQualifiedJavaType()
		);
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getJavaDoc()
	 */
	@Override
	protected String[] getJavaDoc() {
		return new String[]{
			column.getComment(),	
		};
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getMethodDecoration()
	 */
	@Override
	protected MethodDecoration getMethodDecoration() {
		MethodDecoration answer = super.getMethodDecoration(); 
		answer.setFinal(mybatisPlugin.isEntityFinalMethod());
		return answer;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getReturnType()
	 */
	@Override
	protected FullyQualifiedJavaType getReturnType() {
		return getFieldType(introspectSchema.getSchema(), column);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#isBaseType()
	 */
	@Override
	protected boolean isBaseType() {
		return mybatisPlugin.getProjectEnvironmentHolder().isForcePrimitiveType();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getBody()
	 */
	@Override
	protected String[] getBody() {
		return new String[] {
			new StringBuilder()
			.append(JavaKeyWord.RETURN)
			.append(JavaKeyWord.OPERATION_THIS)
			.append(getFieldName(column))
			.toString()
		};
	}
	
	public void setColumn(Column column) {
		this.column = column;
		
	}
	
}
